﻿using System;
using System.Collections.Generic;
using System.Text;
using FirebirdSql.Data.FirebirdClient;
using System.Data;

namespace ConceptCorporateAdmin
{

    public class DbConnection
    {
        FbConnection con = new FbConnection(
                "ServerType=1;User=SYSDBA;" +
                "Password=masterkey;Dialect=3;Database=database/DB.FDB"
                );
        private static DbConnection instance;

        private DbConnection()
        {
            instance = this;
            con.Open();
        }

        public static DbConnection Instance
        {
            get
            {
                if (instance == null) new DbConnection();
                return instance;
            }
        }

        public DataTable Query(String sql)
        {
            DataTable dt     = null;
            try
            {
                FbDataAdapter da = new FbDataAdapter(sql, con);
                DataSet ds = new DataSet();
                da.Fill(ds);
                dt = ds.Tables[0];
            }
            catch (Exception ex)
            {
                Console.WriteLine("SQL = " + sql);
                Console.WriteLine("eroare:" + ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            return dt;
        }

        public void NonQuery(String sql)
        {
            try
            {
                FbCommand cmd = new FbCommand(sql, con);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Console.WriteLine("SQL = " + sql);
                Console.WriteLine("eroare:" + ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
        }
    }

}

